package com.init.bootframe.business.controller;

import com.init.bootframe.business.service.IContactService;
import com.init.bootframe.business.service.ICustomerService;
import com.init.bootframe.business.service.IProductService;
import com.init.bootframe.business.vo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 公司信息controller
 */
@RestController
@RequestMapping("/contact")
public class ContactController {

    @Autowired
    private IContactService contactService; //公司联系信息service

    @Autowired
    private IProductService productService; //产品service

    @Autowired
    private ICustomerService customerService; //客户service

    /**
     * 更新公司信息
     * @param contactVO
     * @return
     * @throws Exception
     */
    @PostMapping("/updateContact")
    public Map<String, Object> updateContact(@RequestBody ContactVO contactVO) throws Exception {
        Map<String, Object> result = contactService.updateContact(contactVO);
        return result;
    }

    /**
     * 后台查询公司信息
     * @return
     */
    @PostMapping("/findContact")
    public List<ContactVO> findContact() {
        return contactService.findContact();
    }


    /**
     * 分页查询公司荣誉信息
     * @param honorVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findHonorList")
    public Map<String, Object> findHonorList(@RequestBody HonorVO honorVO) throws Exception {
        Map<String, Object> result = contactService.findHonorList(honorVO);
        return result;
    }

    /**
     * 添加公司荣誉信息
     * @param honorVO
     * @return
     * @throws Exception
     */
    @PostMapping("/addHonor")
    public Map<String, Object> addHonor(@RequestBody HonorVO honorVO) throws Exception {
        Map<String, Object> result = contactService.addHonor(honorVO);
        return result;
    }

    /**
     * 删除荣誉信息
     * @param honorVO
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteHonor")
    public Map<String, Object> deleteHonor(@RequestBody HonorVO honorVO) throws Exception {
        Map<String, Object> result = contactService.deleteHonor(honorVO);
        return result;
    }

    /**
     * 分页查询公司事件
     * @param eventVO
     * @return
     * @throws Exception
     */
    @PostMapping("/findEventList")
    public Map<String, Object> findEventList(@RequestBody EventVO eventVO) throws Exception {
        Map<String, Object> result = contactService.findEventList(eventVO);
        return result;
    }

    /**
     * 添加公司事件
     * @param eventVO
     * @return
     * @throws Exception
     */
    @PostMapping("/addEvent")
    public Map<String, Object> addEvent(@RequestBody EventVO eventVO) throws Exception {
        Map<String, Object> result = contactService.addEvent(eventVO);
        return result;
    }

    /**
     * 删除公司事件
     * @param eventVO
     * @return
     * @throws Exception
     */
    @PostMapping("/deleteEvent")
    public Map<String, Object> deleteEvent(@RequestBody EventVO eventVO) throws Exception {
        Map<String, Object> result = contactService.deleteEvent(eventVO);
        return result;
    }


    /**
     * 前端查询公司信息
     * @return
     */
    @PostMapping("/webs/selectContact")
    public Map<String, Object> selectContact() {
        Map<String, Object> result = new HashMap<>();

        // 公司联系信息
        List<ContactVO> contactList = contactService.findContact();
        //公司荣誉
        List<HonorVO> honorList = contactService.findHonorList();
        // 公司事件
        List<EventVO> eventList = contactService.findEventList();

        //获取前三条产品信息
        ProductVO productVO = new ProductVO();
        productVO.setLimit(3);
        productVO.setOffset(0);
        List<ProductVO> productList = productService.findProduct(productVO);

        //获取客户信息
        CustomerVO customerVO = new CustomerVO();
        List<CustomerVO> customerList = customerService.findCustomerLists(customerVO);

        result.put("contact",contactList.get(0));
        result.put("honor",honorList);
        result.put("event",eventList);
        result.put("product",productList);
        result.put("customer",customerList);
        return result;
    }


}
